<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let persons = [
            { "username": "xiaoming1", "password": "1111" },
            { "username": "xiaoming2", "password": "222" },
            { "username": "xiaoming3", "password": "33333" }
        ]

        let user = { username: "admin1", password: "12345" }

        var a = persons.findIndex((item) => item.username === user.username)
        a === -1 ? fn() : document.write('用户名已存在')

        function fn() {
            persons.push(user)
            document.write('注册成功')
        }
    </script>
</body>

</html>